package com.itheima.Test;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @PackageName: com.itheima.Test
 * @ClassName: sisuoTest
 * @Author: Renyz
 * @Date: 2021/11/14 23:02
 * @Description: //TODO
 */


public class sisuoTest {

    static ReentrantLock reentrantLock1 = new ReentrantLock();
    static ReentrantLock reentrantLock2 = new ReentrantLock();

    static void test1() throws InterruptedException {
        reentrantLock1.lock();
        Thread.sleep(50);
        System.out.println(Thread.currentThread().getName()+"获取到执行权");
        test2();
        reentrantLock1.unlock();
    }
    static void test2() throws InterruptedException {
        reentrantLock2.lock();
        Thread.sleep(50);
        System.out.println(Thread.currentThread().getName()+"获取到执行权");
        test1();
        reentrantLock2.unlock();
    }



    public static void main(String[] args) {

        new Thread(()->{
            try {
                test1();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
        new Thread(()->{
            try {
                test2();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

    }

}
